package test04;

import java.util.Scanner;

public class LoginFlow {
    private static final int MAX_ATTEMPTS = 3;
    private static final int LOCK_TIME = 120; // in seconds
    private static int attemptCount = 0;
    private static boolean isLocked = false;
    private static String correctPassword = "secret"; // for demonstration purposes

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            if (isLocked) {
                System.out.println("Account is locked for " + LOCK_TIME + " seconds.");
                try {
                    Thread.sleep(LOCK_TIME * 1000); // lock for the specified time
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                isLocked = false; // unlock after the specified time
                attemptCount = 0; // reset attempt count after unlocking
            }

            if (attemptCount >= MAX_ATTEMPTS) {
                System.out.println("You have reached the maximum number of attempts. Please choose your next action:");
                System.out.println("1. Try again");
                System.out.println("2. Exit");
                int choice = scanner.nextInt();
                if (choice == 1) {
                    attemptCount = 0; // reset attempts if user chooses to try again
                } else if (choice == 2) {
                    break; // exit the loop if user chooses to exit
                } else {
                    System.out.println("Invalid choice. Please try again.");
                }
            }

            System.out.println("Enter your password:");
            String inputPassword = scanner.next();

            if (inputPassword.equals(correctPassword)) {
                System.out.println("Password is correct. Account is now in locked state for " + LOCK_TIME + " seconds as a security measure.");
                isLocked = true; // lock the account after successful login
                // In a real application, you might want to perform additional actions here, such as redirecting the user to a new screen or starting a session.
            } else {
                attemptCount++;
                if (attemptCount < MAX_ATTEMPTS) {
                    System.out.println("Password is incorrect. You have " + (MAX_ATTEMPTS - attemptCount) + " attempts left.");
                } else {
                    System.out.println("Password is incorrect. You have reached the maximum number of attempts. Please choose your next action.");
                }
            }
        }

        scanner.close();
        System.out.println("Thank you for using the system. Goodbye!");
    }
}